/**
 * 配置元件
 * 
 */
class ConfigElement {

    /**
     * 用户定义的变量
     * 
     * @param {XMLBuilder} parent 
     * @param {{testname: String, variables: { name: String, value: String, desc: String }[]}} config 
     * @returns
     */
    createUserDefinedVariables(parent, config = { testname: "User Defined Variables", variables: [] }) {
        const { testname, variables } = config;
        const jmxUserDefinedVariables = parent.ele("Arguments", {
            guiclass: "ArgumentsPanel",
            testclass: "Arguments",
            testname: testname
        });
        const jmxCollection = jmxUserDefinedVariables.ele("collectionProp", {
            name: "Arguments.arguments"
        });
        variables.forEach(variable => {
            jmxCollection.ele("elementProp", { name: variable.name, elementType: "Argument" })
                .ele("stringProp", { name: "Argument.name" }).txt(variable.name).up()
                .ele("stringProp", { name: "Argument.value" }).txt(variable.value).up()
                .ele("stringProp", { name: "Argument.metadata" }).txt("=").up()
                .ele("stringProp", { name: "Argument.desc" }).txt(variable.desc);
        });
        jmxUserDefinedVariables.up().ele("hashTree");
    }

    /**
     * HTTP信息头管理器
     * 
     * @param {XMLBuilder} parent 
     * @param {{ testname: String, httpHeaders: {name: String, value: String}[] }} config 
     */
    createHttpHeaderManager(parent, config = { testname: "Http Headers", httpHeaders: [] }) {
        const { testname, httpHeaders } = config;
        const jmxHttpHeaderManager = parent.ele("HeaderManager", {
            guiclass: "HeaderPanel",
            testclass: "HeaderManager",
            testname: testname
        });
        const jmxCollection = jmxHttpHeaderManager.ele("collectionProp", {
            name: "HeaderManager.headers"
        });
        httpHeaders.forEach(httpHeader => {
            jmxCollection.ele("elementProp", { name: "", elementType: "Header" })
                .ele("stringProp", { name: "Header.name" }).txt(httpHeader.name).up()
                .ele("stringProp", { name: "Header.value" }).txt(httpHeader.value);
        })
        jmxHttpHeaderManager.up().ele("hashTree");
    }

}

module.exports = ConfigElement;